package com.chang.rentmall.controllers;
import com.chang.rentmall.beans.PageBean;
import com.chang.rentmall.forms.UserFormBean;
import com.chang.rentmall.services.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class UserController {
    @Autowired
    UserService userService;
    Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping(value = "/users/get/list", method = {RequestMethod.POST})
    public HashMap<String, Object> getUserList(@RequestBody PageBean pageBean) {
        HashMap <String, Object> result = null;
        logger.info("调用接口/users/get/list");
        System.out.println("分页数据 current: " + pageBean.getCurrent());
        System.out.println("分页数据 pageSize: " + pageBean.getPageSize());
        result = new HashMap<String, Object>();
        result.put("code", 200);
        result.put("message", "请求数据成功！");
        return result;
    }
    @RequestMapping(value = "/users/create", method = {RequestMethod.POST})
    public  HashMap<String, Object> createUser (@RequestBody UserFormBean userFormBean) {
        HashMap<String, Object> resukt = null;
        logger.info("调用创建用户: /users/create");
        resukt = userService.addUser(userFormBean.getForm());
        return resukt;
    }
    @RequestMapping(value = "/users/detail", method = {RequestMethod.POST})
    public HashMap<String, Object> getUserById (@RequestBody UserFormBean userFormBean) {
        logger.info("获取用户信息详情: /users/detail");
        return userService.getUserById(userFormBean.getQuery().getId());
    }
}
